package com.jckl.foodathon.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.jckl.foodathon.R;
import com.jckl.foodathon.model.Brand;
import com.jckl.foodathon.services.config.GetAllBrandInfo;
import com.jckl.foodathon.services.config.NewBrandConfiguration;

public class BrandFragment extends Fragment implements OnClickListener{
	
	//Screen input
	EditText name;
	Button save;
	Button refresh;
	Brand brand;
	
	public BrandFragment () {
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_brand, container, false);
		
		save		= (Button) view.findViewById(R.id.btn_brand_save);
		save.setOnClickListener(this);
		refresh 	= (Button) view.findViewById(R.id.btn_brand_refresh);
		refresh.setOnClickListener(this);
		
		
		name			= (EditText) view.findViewById(R.id.brand_name);
		
		return view;
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.btn_brand_save:
			saveStoreData();
		case R.id.btn_brand_refresh:
			refresh();
		break;
		}
	}
	
	private void setDataToObject(){
		brand = new Brand();
		brand.setName(name.getText().toString());
	}

	private void saveStoreData(){
		setDataToObject();
		NewBrandConfiguration brandConfig = new NewBrandConfiguration();
		brandConfig.perform(getActivity(), brand);
	}
	
	private void refresh(){
		GetAllBrandInfo brandInfo = new GetAllBrandInfo();
		brandInfo.perform(getActivity());
	}
}
